<!--
 * @Author: your name
 * @Date: 2021-09-10 11:33:38
 * @LastEditTime: 2021-09-13 15:16:58
 * @LastEditors: LAPTOP-JN5U4VA6
 * @Description: In User Settings Edit
 * @FilePath: \ej-webui\src\pages\examine\accountChange.vue
-->
<template>
  <div class="production">
    <div class="btns">
      <!-- 检索框 -->
      <el-form :inline="true" :model="params" size="small">
        <el-form-item>
            <el-date-picker
                v-model="params.applyTime"
                type="daterange"
                align="right"
                unlink-panels
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions"
                format="yyyy 年 MM 月 dd 日"
                value-format="yyyy-MM-dd hh:mm:ss">
            </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-select clearable v-model="params.status" placeholder="请选择类型">
            <el-option label="充值" value="充值"></el-option>
            <el-option label="提现" value="提现"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select clearable v-model="params.status" placeholder="请选择状态">
            <el-option label="未审核" value="未审核"></el-option>
            <el-option label="通过" value="通过"></el-option>
            <el-option label="不通过" value="不通过"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-input clearable v-model="params.userId" placeholder="请输入申请人编号"></el-input>
        </el-form-item>
        <el-button
          type="primary"
          size="small"
          style="margin-right: 10px"
          @click="pageQueryProductions"
          icon="el-icon-search"
          >查询</el-button
        >
      </el-form>
    </div>
    <div class="content">
      <!-- 表格 -->
      <el-table :data="resData.list" style="width: 100%" size="small"  ref="multipleTable">
        <!-- fixed  表示将对应的列进行固定 -->
        <el-table-column type="index" label="序号" ></el-table-column>
        <el-table-column label="申请人编号" prop="userId" align="center"></el-table-column>
        <el-table-column label="申请时间" prop="applyTime" width="150" align="center">
          <template v-slot="scope">
            {{scope.row.applyTime | fmtDate}}
          </template>
        </el-table-column>
        <el-table-column label="变更类型" prop="applyType" align="center"></el-table-column>
        <el-table-column label="变更资金" prop="money" align="center">
          <template v-slot="scope">
            ￥<span style="color: #e65d6e; font-size:18px;">{{scope.row.money}} </span>元
          </template>
        </el-table-column>
        <el-table-column label="变更原因" prop="reason" align="center"></el-table-column>
        <el-table-column label="变更状态" prop="status" align="center">
          <template v-slot="scope">
            <el-tag
              v-if="scope.row.status == '通过'"
              size="mini"
              type="success"
              >{{ scope.row.status }}</el-tag>
              <el-tag
              v-else-if="scope.row.status == '不通过'"
              size="mini"
              type="danger"
              >{{ scope.row.status }}</el-tag>
              <el-tag
              v-else
              size="mini"
              type="info"
              >{{ scope.row.status }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作"  align="center">
          <template v-slot="scope">
            <el-button type="text" size="small" @click="editHandler(scope.row.id,$event)">通过</el-button>
            <el-button type="text" size="small" @click="editHandler(scope.row.id,$event)" style="color:rgb(175, 33, 194)">不通过</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <!-- total表示：数据的总条数  current-page表示：当前所在的页数   -->
      <el-pagination
        background
        layout="prev, pager, next, sizes"
        :total="resData.total"
        :page-size="params.pageSize"
        :current-page="params.page"
        @current-change="pageChangeHandler"
        :page-sizes="[5, 10, 15]"
        @size-change="pageSizeChangeHandler"
      >
      </el-pagination>
    </div>
  </div>
</template>
<script>
import request from "@/utils/request";
import { mapActions } from "vuex";
import _ from "lodash";

export default {
  data() {
    return {
      params: {
        page: 1,
        pageSize: 5,
      },
      resData: {},
      categories: [],
      title: "",
      production: {},

      // 时间选择器
        pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
    }
  },
  methods: {
    // 导入状态机中的方法
    ...mapActions("category", ["findAllCategories"]),
    // 分页查询产品表格
    async pageQueryProductions() {
      // 过滤数据将空字符串删除
      for (let key in this.params) {
        if (this.params[key] == "") {
          delete this.params[key];
        }
      }
      let res = await request.get("/accountApply/pageQueryAccountApply", {
        params: this.params,
      });
      this.resData = res.data;
    },
    // page改变事件  
    pageChangeHandler(page) {
      // 将更新了的页码传递给页面   并且刷新查询到的对应页码上的内容
      this.params.page = page;
      this.pageQueryProductions();
    },
    // pageSize改变事件  pageSize是每页中显示的数据条目
    pageSizeChangeHandler(pageSize) {
      this.params.pageSize = pageSize;
      this.pageQueryProductions();
    },

    // 关闭模态框的回调函数
    dialogCloseHandler() {
      // 置空表单验证
      this.$refs["saveForm"].resetFileds();
    },

    // 编辑 事件
    // 编辑按钮  事件函数
    editHandler(id,e) {
      this.$confirm('是否确认该操作?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (e.target.innerText == "不通过"){
            request.get("/accountApply/checkNoPass",{ params: { id }}).then((res) => {
              // 重载数据  重新刷新页面中的数据
              this.pageQueryProductions();
              // 提示信息
              this.$message.success(res.message);
            });
          } else {
            request.get("/accountApply/checkPass",{ params: { id }}).then((res) => {
              this.pageQueryProductions();
              this.$message.success(res.message);
            })
          }
        });
    },
    
  },
  created() {
    this.pageQueryProductions(); // 分页查询产品
    this.findAllCategories().then((res) => {
      this.categories = res.data.list;
    }); // 查询所有产品栏目
  },
};
</script>

<style scoped>

</style>